#include <iostream>
#include <sys/types.h>
#include <unistd.h>

const int num = 10;

void Worker()
{
    int cnt = 12;
    while (cnt--)
    {
        std::cout << "child " << getpid() << " is running, cnt: " << cnt << std::endl;
        sleep(1);
    }
}
int main()
{
    for (int i = 0; i < num; i++)
    {

    }
    return 0;
}

/*
int main()
{
    std::cout << "before fork: I am a process, pid: " << getpid();
    std::cout << ", ppid: " << getppid() << std::endl;

    sleep(3);
    std::cout << "开始创建进程了!" << std::endl;
    sleep(2);
    pid_t id = fork();
    if (id < 0)
        return 1;
    else if (id == 0)
    {
        // 子进程
        std::cout << "after fork, 我是子进程: I am a process, pid: " << getpid();
        std::cout << ", ppid: " << getppid();
        std::cout << ", return id: " << id << std::endl;
        sleep(2);
    }
    else
    {
        std::cout << "after fork, 我是父进程: I am a process, pid: " << getpid();
        std::cout << ", ppid: " << getppid();
        std::cout << ", return id: " << id << std::endl;
        sleep(2);
    }
    return 0;
}

int main()
{
    std::cout << getpid() << std::endl;
    std::cout << "更改当前的工作目录之前!" << std::endl;
    sleep(20);
    chdir("/home/sheep");
    std::cout << "更改当前的工作目录之后!" << std::endl;
    sleep(10);

    FILE *fp = fopen("sheep.txt", "w");
    if (fp == nullptr)
        return 1;
    fclose(fp);

    std::cout << "新建文件完成" << std::endl;
    sleep(3);
    return 0;
}
*/